home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / addpcx.zip / PCXSHOW.C < prev    next >
C/C++ Source or Header  |  1988-06-21  |  6KB  |  278 lines

  1. /*    PCXshow.c   -  Simple PCX Slide Show for all three video boards.
  2.  
  3.     Note: sorry, I was too busy to write the routines to convert
  4.           pictures from one format to another. This routine will
  5.           actually display any picture on any adapter, but the
  6.           results will look funny in some cases.
  7. */
  8.  
  9.  
  10. #define ALLOCATE
  11. #include <stdio.h>
  12. #undef NULL
  13. #include "lib.h"
  14. #include <fcntl.h>
  15. #include "pcx.h"
  16. #include <ibmtimer.h>
  17.  
  18. #define stopwatch( r,p ) (ibmpc_stopwatch((r),(p)) / IBMPC_TIMER0_FREQ)
  19.  
  20. char *spec;
  21.  
  22. int show_flg = 0;
  23. long show_time = 10; /* 10 seconds per picture... */
  24. struct IBMPC_STOPWATCH timer;
  25. int inverse = 0;
  26. int palette = 0;
  27.  
  28.  
  29. char language = 'E';
  30.  
  31.  
  32. main( argc, argv )
  33. char **argv;
  34. int argc;
  35. {
  36.     int i;
  37.  
  38.     if ( argc < 2 )
  39.     {  help();
  40.        exit(1);
  41.     };
  42.  
  43.     for ( i=1; i < argc; i++ )
  44.        if ( *argv[i] == '-' )
  45.           check_option( argv[i]+1 );
  46.  
  47.     if ( vgr_setup( spec ) )
  48.        CRASH("vgr_setup failed!");
  49.  
  50.     if ( vgr_type == TYPE_UNKNOWN )
  51.        CRASH( "ERROR: Can't Identify Video Board!" );
  52.     if ( vgr_type == TYPE_MDA )
  53.        CRASH( "ERROR: Requires a graphic board" );
  54.  
  55.     printf("%s Video Board Detected\n", vgr_type_name );
  56.     printf("hit return to continue, or ^C to exit:");
  57.     getchar();
  58.  
  59.     for ( i=1; i < argc; i++ )
  60.        if ( *argv[i] != '-' )
  61.           dmppcx( argv[i] );
  62.  
  63.     enjoy();
  64.     if ( show_flg )
  65.        vgr_mode( 3 );
  66. }
  67.  
  68.  
  69. check_option( opt )
  70. char *opt;
  71. {
  72.          if ( *opt == 'd' )
  73.             show_time = atoi( opt + 1 );
  74.     else if ( *opt == 'i' )
  75.             inverse = 1;
  76.     else if ( *opt == 'n' )
  77.             inverse = 0;
  78.     else if ( *opt == 'p' )
  79.             palette = 1;
  80.     else if ( !strcmp( opt, "cga" ) )
  81.             spec = opt;
  82.     else if ( !strcmp( opt, "ega" ) )
  83.             spec = opt;
  84.     else if ( !strcmp( opt, "cga2" ) )
  85.             spec = opt;
  86.     else if ( !strcmp( opt, "herc" ) )
  87.             spec = opt;
  88.     else if ( *opt == '?' )
  89.             help();
  90.     else {  printf( "unknown option: %s, try \"PCXDISP -?\"\n", opt );
  91.             exit(1);
  92.          };
  93. }
  94.  
  95.  
  96. dmppcx( fn )
  97. char *fn;
  98. {
  99.     PCXPIC *pic, *load_picture();
  100.  
  101.     pic = load_picture( fn );
  102.  
  103.     if (inverse) 
  104.        pcx_invert_pic( pic );
  105.  
  106.     if ( palette && vgr_type == TYPE_EGA )
  107.        play_with_palette( pic );
  108.     else display_picture( pic );
  109.  
  110.     pcx_free_pic( pic );
  111. }
  112.  
  113.  
  114. PCXPIC *load_picture( fn )
  115. char *fn;
  116. {
  117.     PCXPIC *pic, *pcx_init_pic();
  118.     FILE *fp, *fopen();
  119.  
  120.     if ( ! (fp = fopen( fn, "r" )) )
  121.     {  printf( "error opening file: %s\n", fn );
  122.        CRASH("");
  123.     };
  124.  
  125.     if ( !( pic = pcx_init_pic( 0, 0, 0 ) ) )
  126.        CRASH( "out of memory" );
  127.  
  128.     if ( pcx_read_pic( pic, fp ) )
  129.     {  printf( "pcx_read_pic failed reading %s", fn );
  130.        CRASH("");
  131.     };
  132.  
  133.     fclose(fp);
  134.     return pic;
  135. }
  136.  
  137.  
  138. display_picture( pic )
  139. PCXPIC *pic;
  140. {
  141.     enjoy();
  142.     if ( (*vgr_nit)() )
  143.        CRASH( "Board init failed" );
  144.     if ( VGR_MODE( vgr_md ) )
  145.        CRASH( "Mode select failed" );
  146.  
  147.     VGR_CLEAR();
  148.  
  149.     pcx_showpic( pic, 0, 0, 0 );
  150.  
  151.     stopwatch( 1, &timer );
  152.     show_flg = 1;
  153. }
  154.  
  155.  
  156. enjoy()
  157. {
  158.     int c = 0;
  159.  
  160.     if ( show_flg )
  161.        while ( stopwatch( 0, &timer ) < show_time )
  162.           if ( constat() )
  163.              if ( (c = conin()) == 27 || c == 32 )
  164.                 break;
  165.              else printf("\007");
  166.  
  167.     if ( c == 27 )
  168.     {  vgr_mode( 3 );
  169.        exit(0);
  170.     };
  171. }
  172.  
  173.  
  174. play_with_palette( pic )
  175. PCXPIC *pic;
  176. {
  177.     char buf[64];
  178.     int p, c, r, g, b;
  179.  
  180.     p = r = g = b = 0;
  181. top:    vgr_mode( 3 );
  182.     printf("Palette=%d, R%d G%d B%d\n", p, r, g, b );
  183.     printf("p#, r#, g# or b#:");
  184.     gets(buf);
  185.  
  186.     if ( *buf )
  187.     {  if ( *buf == 'r' )
  188.           r = atoi(buf+1);
  189.        if ( *buf == 'g' )
  190.           g = atoi(buf+1);
  191.        if ( *buf == 'b' )
  192.           b = atoi(buf+1);
  193.        if ( *buf == 'p' )
  194.           p = atoi(buf+1);
  195.     };
  196.  
  197.     show_flg = 0;
  198.     display_picture( pic );
  199. pal:    r &= 0x03; g &= 0x03; b &= 0x03; p &= 0x0f;
  200.     ega_set_palette( p, r, g, b );
  201.  
  202. /*    This is intended to generate a different sound for
  203.     each palette setting...
  204.  
  205.     sound( 500 + ( (b & 0x01)     | !!(b & 0x02) *  8
  206.                | !!(g & 0x01) * 2 | !!(g & 0x02) * 16
  207.                | !!(r & 0x01) * 4 | !!(r & 0x02) * 32 )
  208.                    * 100, 10 );
  209. */
  210.     while ( (c=conin()) != 27 && c != 3 && c != '+' && c != '-' )
  211.        printf("\007");
  212.  
  213.     if ( c == 3 )
  214.     {  vgr_mode( 3 );
  215.        exit(0);
  216.     };
  217.  
  218.     if ( c == '+' || c == '-' )
  219.        if ( *buf == 'r' || *buf == 'g' || *buf =='b' )
  220.        {  if ( *buf == 'r' )
  221.              r += (c=='+') ? 1 : -1;
  222.           if ( *buf == 'g' )
  223.              g += (c=='+') ? 1 : -1;
  224.           if ( *buf == 'b' )
  225.              b += (c=='+') ? 1 : -1;
  226.           goto pal;
  227.        };
  228.  
  229.     goto top;
  230. }
  231.  
  232.  
  233. help()
  234. {
  235.     printf( "\
  236. usage: PCXDISP [options...] [file_refs...]\n\
  237. \n\
  238.        PCXDISP is a simple slide show utility. Each .PCX file\n\
  239.        listed is shown for a period of time. Options are as follows:\n\
  240. \n\
  241.        -cga   force CGA 640x200x2 mode\n\
  242.        -cga2  force CGA 320x200x4 mode\n\
  243.        -ega   force EGA 640x350x16 mode\n\
  244.        -herc  force HERC 720x348x2 mode\n\
  245.        -dnn   set the delay between 'slides' to <nn> seconds\n\
  246.        -i     Invert all bits in the image before displaying\n\
  247.        -n     Stop inverting bits in the image\n\
  248.        -p     Allow interactive tinkering with palette registers\n\
  249.               works only in EGA mode; try ESC, ^C, +, -, r, g & b keys.\n\
  250.        -?     Show this help message\n" );
  251.        exit(1);
  252. }
  253.  
  254.  
  255. typedef struct __REGS {
  256.     int ax, bx, cx, dx,
  257.         si, di, ds, es;
  258. } __regs;
  259.  
  260. int conin()
  261. {
  262.     __regs r;
  263.  
  264.     r.ax = 0;
  265.     sysint( 0x16, &r, &r );
  266.     return r.ax & 0xff;
  267. }
  268.  
  269. int constat()
  270. {
  271.     __regs r;
  272.  
  273.     r.ax = 0x0100;
  274.     return !( sysint( 0x16, &r, &r ) & 0x0040 );
  275. }
  276.  
  277.  
  278.